//提交订单
function odrsubmit(openid, pro, addr, num = 1){
 
  var url ="https://www.7zao.com/o/odr/"+openid+"/"+pro+"/"+addr;
  wx.request({
    url: url, //仅为示例，并非真实的接口地址      
    header: {
      'content-type': 'application/json'
    },
    success: function (res) {
        console.log(res);
    }
  });
}

/***
 * 合计金额
 * act 活动信息
 * num 数据量
 * money 单价
 * ship运费
 */
function activity(act,num,money,ship){

  var hesuan=money*num;//产品金额
  hesuan = hesuan < 38 ? hesuan + 10 : hesuan;
  //扣除金额折后金额
  if(act.length>0){
      act=act[0];
      var prostr = "";//赠送产品
      if (act.actvcate == 2) {
        if (act.actvstatus == 3) {
          //折扣价
          if (act.actvtype == 1) {
            hesuan =(act.acttif / 10) * hesuan;
          }
          if (act.actvtype == 2 && act.actvif <= num) {
            hesuan =(act.acttif / 10) * hesuan;
          }

          if (act.actvtype == 3 && act.actvif <= hesuan) {
            hesuan =(act.acttif / 10) * hesuan;
          }
          prostr = act.acttif+'折';
        }else{
          //赠减金额
          if (act.actvtype == 1) {
            hesuan = hesuan - act.acttif;
          }
          if (act.actvtype == 2 && act.actvif <= num) {
            hesuan = hesuan - act.acttif;
          }

          if (act.actvtype == 3 && act.actvif <= hesuan) {
            hesuan = hesuan - act.acttif;
          }
          prostr = '-￥' + act.acttif;
        }
      }
     
      if (act.actvcate == 1) {
        if (act.actvtype == 1) {
          prostr = act.acttif;
        }
        if (act.actvtype == 2 && act.actvif >= num) {
          prostr = act.acttif;
        }

        if (act.actvtype == 3 && act.actvif <= hesuan) {
          prostr = act.acttif;
        }
      }
    }
      var sul = new Array();
      sul['mn'] = Math.floor(hesuan*100)/100;  
      sul['pro'] = prostr;
      return sul;  

}

module.exports.odrsubmit = odrsubmit
exports.activity = activity
